package com.example.mvvm

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

class DemoActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_demo)
        findViewById<View>(R.id.show_dialog).setOnClickListener {
            showDialog()
        }
        findViewById<View>(R.id.other).setOnClickListener {
            Log.e("DemoActivity" , "asdasdasdsd")
            startActivity(Intent(DemoActivity@this , MainActivity::class.java))
        }
    }

    fun showDialog() {
        val content = findViewById<View>(android.R.id.content)
        val decorView = this.window.decorView;
        Log.e("DemoActivity" , "decorView -> ${decorView.x}, ${decorView.y}, ${decorView.width}, ${decorView.height}")
        Log.e("DemoActivity" , "content -> ${content.x}, ${content.y},  ${content.width}, ${content.height}")

        if(content is ViewGroup){
            val inflate =
                View.inflate(this, R.layout.view_layer, null)
            val findViewById = inflate.findViewById<View>(R.id.hide)
            findViewById.setOnClickListener {
                content.removeView(inflate)
            }
            content.addView(inflate)
        }
    }
}